package com.freshcity.page.wait
{
	import com.freshcity.component.container.Component;
	import com.freshcity.core.OpCodes;
	import com.freshcity.graphics.LineInfoBack;
	import com.freshcity.graphics.StopItem;
	
	import flash.events.MouseEvent;

	public class LineInfo extends Component
	{
		public var owner:RoomList;
		
		private var background:LineInfoBack;
		private var line:*;
		private var room:*;
		
		public function LineInfo(line:*,room:*, xpos:Number=0,ypos:Number=0)
		{
			this.line=line;
			this.room=room;
			//this.width = 345;
			//this.height = 110;
			super(null,xpos,ypos);			
		}		
		
		override protected function addChildren():void
		{
			super.addChildren();
			background=new LineInfoBack();
			background.nameLabel.text=line.name;
			
			initStations(line.stations);
			addChild(background);
			
			background.preBtn.addEventListener(MouseEvent.CLICK, onPre);
			background.nextBtn.addEventListener(MouseEvent.CLICK, onNext);
		}
		
		override public function draw():void
		{
			super.draw();
		}

		protected function onNext(event:MouseEvent):void
		{
			owner.queryRoom = room;
			owner.lineBox.x = 390;
			owner.win.removeChild(owner.lineBox);
			owner.group.commu.send(OpCodes.NEXT_STOP, {lid: line.id, sid: room.station, direction: "up"});
		}

		protected function onPre(event:MouseEvent):void
		{
			owner.queryRoom = room;
			owner.lineBox.x = 390;
			owner.win.removeChild(owner.lineBox);
			owner.group.commu.send(OpCodes.NEXT_STOP, {lid: line.id, sid: room.station, direction: "down"});
		}

		private function initStations(data:String):void
		{
			var dataArray:Array=data.split(",");

			var l:int=dataArray.length - 1;
			var stepX:Number=260 / l;
			var currentX:Number=10;
			var currentY:Number=25;
			for each (var name:* in dataArray)
			{
				var item:StopItem=new StopItem();
				item.y=currentY;
				item.x=currentX;
				item.nameLabel.text=name;
				background.addChild(item);
				currentX+=stepX;
			}
		}
	}
}